

def load(bt_backup):

    import os
    from tqdm import tqdm
    from pathlib import Path
    # 获取BT_backup下所有的fastresume文件的绝对路径
    file_list = os.listdir(bt_backup)
    bt_backup = Path(bt_backup).resolve()
    
    # 获取fastresume、torrent文件的绝对路径（需要保证每个fastresume都有对应的torrent存在）
    file_list = [x for x in file_list if x.endswith('.fastresume') or x.endswith('.torrent')]
    ordered_file_list = sorted(file_list)
    fastresume_list = [bt_backup / x for x in ordered_file_list[::2]]
    torrent_list = [bt_backup / x for x in ordered_file_list[1::2]]

    # 构建目录树
    torrent_list = []
    for i in tqdm(range(len(fastresume_list)), desc='build directory tree'):
        with open(fastresume_path, 'rb') as f:
            fastresume = bencode.decode(f.read())
        with open(torrent_path, 'rb') as f:
            torrent = bencode.decode(f.read())

        file_name = torrent['info']['name']
        byte_len = 0
        if torrent.get('info').get('length') is not None:
            byte_len = torrent['info']['length']
        else:
            for f in torrent['info']['files']:
                byte_len += f['length']

        refined_info = {
            'name': file_name,
            'hash': Path(torrent_path).stem,
            'length': byte_len,
            'fastresume': str(fastresume_path),
            'torrent': str(torrent_path),
            'file_path': fastresume['qBt-savePath'],
        }
        self.torrents[refined_info['hash']] = refined_info
        return refined_info
        directory.add_torrent(info_dict['file_path'], info_dict['hash'])

    
    print('prepare complete.')